<?php
/* 
 *  意见反馈
 *  传参 幼儿园 id
 *  */
namespace Home\Controller;

class FeedBackController extends ComController{
	//意见反馈
	public function index(){

		if(IS_POST){
			$data = $_POST;
			if(empty($data['content'])){
				echo json_error('反馈内容不能为空，请输入内容');
				die;
			}
			$data['sc_id'] = $data['id']?(int)$data['id']:'';
			unset($data['id']);
			//用户id
			$data['user_id']=1;
			if(empty($data['sc_id'])){
				echo json_error('参数错误，请重新选择',array('url'=>'window.history.go(-1);'));
				die;
			}
			$data['add_time']=time();
			//将反馈的数据写入数据库
			$feed = M('feed_back');
			$res = $feed->add($data);
			if($res){
				echo json_success('您的反馈已提交，感谢您的意见');
				die;
			}else{
				echo json_error('意见反馈提交失败，请重新提交');
				die;
			}
			
		}else{
			//以get方式接收幼儿园id
			$sc_id = isset($_GET['uid'])?(int)$_GET['uid']:'';

			if(empty($sc_id)){
				//传参错误，请重新选择
				$this->notice('','传参错误，请重新选择');
				die;
			}else{
				$where['uid']=$sc_id;
			}
			//查询幼儿园信息，前台显示
			$member = M('member');
			$data = $member->field('uid,phone')->where($where)->find();
			$this->assign('data',$data);
			$this->display();
		}
	}
	
	
	/* 前台通知 */
	
	public function notice($url='',$msg=''){
	
		if(!empty($msg)){
			$data['msg']=$msg;
		}
		if(empty($url)){
			$data['url'] = $_SERVER['HTTP_REFERER']?$_SERVER['HTTP_REFERER']:"javascript:window.history.go(-1)";
		}else{
			$data['url']=$url;
		}
		$this->assign('data',$data);
		$this->display("Public:notice");
	
	}
}

